package org.jin.samples.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.jin.samples.dao.IScoreDao;
import org.jin.samples.dao.ITestDao;
import org.jin.samples.dao.IUserSubjectDAO;
import org.jin.samples.model.ExamScore;
import org.jin.samples.model.ExamSubject;
import org.jin.samples.model.ExamTest;
import org.jin.samples.model.ExamUser;
import org.jin.samples.model.ExamUserSubject;
import org.jin.samples.model.vo.ExamScoreVO;
import org.jin.samples.model.vo.ExamSubjectVO;
import org.jin.samples.model.vo.ExamUserVO;
import org.jin.samples.page.PagerModel;
import org.jin.samples.service.IScoreService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"file:WebContent/WEB-INF/viewspace-servlet.xml"})
public class score {
	
	@Autowired
	private IScoreDao scoreDao;
	
	@Autowired
	private IScoreService scoreService;
	
	@Autowired
	 private IUserSubjectDAO userSubjectDAO;
	
	@Autowired
	private ITestDao testDao;
	
	@Test
	public void test1(){
		List<ExamScore> list = scoreDao.findAllByScoreId("1");
		for(ExamScore es : list){
			System.out.println(es.getId());
		}
	}
	
	@Test
	public void test2(){
		List<ExamScore> list = scoreService.findAllByScoreId("1");
	}
/*	
	@Test
	public void test3(){
		List<ExamSubject> list = scoreService.findAllBySubjectId(1);
		for(ExamSubject es: list){
			System.out.println("es.getName()"+es.getName());
		}
	}*/
	
	@Test
	public void test4(){
		PagerModel<ExamUserSubject> list = userSubjectDAO.findAllSubjectByUserIdPage("1");
		for(ExamUserSubject eus : list.getDates()){
			System.out.println("eus.getSubject().getName()="+eus.getSubject().getName());
			System.out.println("eus.getUser().getUserName()="+eus.getUser().getUserName());
		}
		System.out.println("list.getOffset()="+list.getOffset());
		System.out.println("list.getPageSize()="+list.getPageSize());
		System.out.println("list.getPageSize()="+list.getTotalSize());
	}
	
	@Test
	public void test5(){
		try {
			ExamScoreVO esVO = scoreService.findScoreByUSId("1", 1);
			System.out.println("esVO.getSubjectId()="+esVO.getSubjectId());
			System.out.println("esVO.getUserId()="+esVO.getUserId());
			System.out.println("esVO.getScore()="+esVO.getScore());
			System.out.println("esVO.getExamTime()="+esVO.getExamTime());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void test6(){
		System.out.println("吗的你在不在啊******");
		List<ExamTest> et = testDao.findAllBySubId(1);
		System.out.println("我第二条是没病的*****");
		if(et==null){
			System.out.println("空B啊");
		}
		for(ExamTest e : et){
			System.out.println("为什么没有输出");
			System.out.println("e.getContent()="+e.getContent());
			System.out.println("e.getExamSubject()="+e.getExamSubject());
			System.out.println("e.getExamTestType()="+e.getExamTestType());
			System.out.println("e.getId()="+e.getId());
		}
		
	}
	
/*	@Test
	public void test7() throws Exception{

		scoreService.addScore(esVO);
		System.out.println("******添加成功*******");
	}
	*/
	@Test
	public void Test9() throws Exception{
		ExamScore es = new ExamScore();
		ExamUser eu = new ExamUser();
		ExamSubject subject = new ExamSubject();
		
		eu.setUserId("5");
		subject.setSubId(1);
		
		es.setId(0);
		es.setScore(20);
		es.setSubjectId(subject);
		es.setUserId(eu);
		
		String str = "2017-06-07 19:32:30";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = sdf.parse(str);
		
		System.out.println("date"+date);
		es.setExamTime(date);
		
		scoreDao.save(es);
		System.out.println("****添加成功***");
	}
	
	
	@Test
	public void test8() throws Exception{
		String str = "2017-06-07 19:32:30";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date =sdf.parse(str);
		System.out.println("date="+date);
	}
	
}
